/**
 * 进行安全验证，为调用功能性js-api的前提
 * @since 1.0.0
 * @returns {Promise} 返回一个是否通过安全验证的信息
 * @example
 * 
 * authCheckApp().then(res => {}).catch(err => {})
 */

function authCheckApp() {
    let jsSession = sessionStorage.getItem('jsSession')
    let resultData = {
        msg: '',
        status: ''
    }
    return new Promise((reslove, reject) => {
        if (jsSession === undefined || jsSession === '' || jsSession === null) {
            resultData.status = -1
            resultData.msg = '未登录'
            reject(resultData)
        }
        window.WebViewJavascriptBridge.callHandler('authCheckApp', {
            'session': jsSession
        }, (response) => {
            if (typeof response === 'string') {
                response = JSON.parse(response)
            }
            if (response.status === 0) {
                resultData.status = 0
                resultData.msg = '认证成功'
                reslove(resultData)
            } else {
                resultData.stutas = response.status
                resultData.msg = response.msg
                reject(resultData)
            }
        })
    })
}

export default authCheckApp